package com.intellagric.service.impl.module.sys_user_log;

import com.github.pagehelper.PageHelper;
import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.mapper.SysUserLogMapper;
import com.intellagric.pojo.SysUserLog;
import com.intellagric.pojo.SysUserLogExample;
import com.intellagric.pojo.SysUserLogWithBLOBs;
import com.intellagric.service.module.sys_user_log.UserLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/10/30
 * @DESC： 用户操作日志管理服务实现
 */
@Service
public class UserLogServiceImpl implements UserLogService {

    @Autowired
    private SysUserLogMapper userLogMapper;

    /**
     * 添加用户日志信息
     * @param sysUserLogWithBLOBs
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage addUserLog(SysUserLogWithBLOBs sysUserLogWithBLOBs) {
        if (userLogMapper.insertSelective(sysUserLogWithBLOBs) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 删除用户日志信息
     * @param id
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage deleteUserLog(String id) {
        if (userLogMapper.deleteByPrimaryKey(id) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 通过查询用户日志信息
     * @param id
     * @return SysUserLog
     */
    @Override
    public SysUserLog getUserLogById(String id) {
        return userLogMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询用户日志信息列表
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getUserLogList() {
        SysUserLogExample userLogExample = new SysUserLogExample();
        userLogExample.createCriteria().andIdIsNotNull();
        List<SysUserLog> userLogList = userLogMapper.selectByExample(userLogExample);
        return LayuiDataGridResult.success().add(userLogList,userLogList.size());
    }

    /**
     * 分页查询用户日志信息
     * @param page
     * @param rows
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getUserLogPage(int page, int rows) {
        PageHelper.startPage(page,rows);
        SysUserLogExample userLogExample = new SysUserLogExample();
        userLogExample.createCriteria().andIdIsNotNull();
        List<SysUserLog> userLogList = userLogMapper.selectByExample(userLogExample);
        return LayuiDataGridResult.success().add(userLogList,userLogList.size());
    }
}
